package com.bw.task.mvp.persenter;

import android.util.Log;

import com.blankj.utilcode.util.LogUtils;
import com.bw.library.mvp.presenter.BasePresenter;
import com.bw.task.bean.ImgBean;
import com.bw.task.bean.MoneyBean;
import com.bw.task.bean.PopupWindioBean;
import com.bw.task.bean.UserBean;
import com.bw.task.mvp.contern.UserContent;

import org.jetbrains.annotations.NotNull;

import java.nio.file.attribute.UserPrincipal;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class UserPersenter extends BasePresenter<UserContent.mView,UserContent.mModel> {

    private static final String TAG = "UserPersenter";
    public UserPersenter(UserContent.mView mView, UserContent.mModel mModel) {
        super(mView, mModel);
    }
    public void register(String name, String pass){
        mModel.rquestreg(name, pass, new Observer<UserBean>() {
            @Override
            public void onSubscribe(@NotNull Disposable d) {
                Log.i(TAG, "onSubscribe: ");
            }

            @Override
            public void onNext(@NotNull UserBean userBean) {
                mView.UserBean(userBean);
            }

            @Override
            public void onError(@NotNull Throwable e) {
                Log.i(TAG, "onError: 已有账户请重新注册");
            }

            @Override
            public void onComplete() {
                Log.i(TAG, "onComplete: ");
            }
        });
    }

    public void login(String name,String pass){
        mModel.rquestlog(name, pass, new Observer<UserBean>() {
            @Override
            public void onSubscribe(@NotNull Disposable d) {

            }

            @Override
            public void onNext(@NotNull UserBean userBean) {
                LogUtils.i(userBean);
                mView.LogUserBean(userBean);

            }

            @Override
            public void onError(@NotNull Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    public void getimg(String path){
        mModel.requestimg(path, new Observer<ImgBean>() {
            @Override
            public void onSubscribe(@NotNull Disposable d) {

            }

            @Override
            public void onNext(@NotNull ImgBean imgBean) {
                mView.getImgBean(imgBean);
            }

            @Override
            public void onError(@NotNull Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    public void getmonry(String id,String money){
        mModel.requestmoney(id, money, new Observer<MoneyBean>() {
            @Override
            public void onSubscribe(@NotNull Disposable d) {

            }

            @Override
            public void onNext(@NotNull MoneyBean userBean) {
                mView.MoneyUserBean(userBean);
            }

            @Override
            public void onError(@NotNull Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }


}
